# 导包
import jsonschema

# 书写校验规则
schema = {
    "type":"object",   # type 这里描述的是整个校验数据的类型，即data的类型
    "properties":{     # properties 这里描述的是校验数据里面细分的数据类型
        "success": {"type":"boolean"},
        "code": {"type":"integer"},
        "message": {"type":"string"},
        "money": {"type":"number"},
        "address":{"type":"null"},
        "data": {
            "type":"object",
            "properties":{
                    "name": {"type":"string"},
                    "age": {"type":"integer"},
                    "height":{"type":"number"}
                }
        },
        "luckyNumber": {"type":"array"}
        }
}
# 校验数据
data = {
    "success": True,
    "code": 10000,
    "message": "操作成功",
    "money": 6.66,
    "address": None,
    "data": {
        "name": "tom",
        "age": 19,
        "height": 1.66
    },
"luckyNumber": [6, 8, 9]
}

# 调用validate 方法 实现校验
result =jsonschema.validate(instance=data,schema=schema)
print(f"result={result}")
